package com.py.korona.db.model;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import com.py.korona.db.UriBuilder;
import com.py.korona.db.model.base.Entity;
import com.py.korona.db.model.base.EntityDescription;
import com.py.korona.db.model.base.EntityProperty;

public class CategoryEntity extends Entity {
    public static String             FieldNameID   = "_id";
    public static String             FieldNameText = "text";
    public static String             TableName     = "category";
    private static EntityDescription entityDescription_;

    public static EntityDescription entityDescription() {
        if (null == entityDescription_) {
            entityDescription_ = new EntityDescription();
            entityDescription_.addProperty(new EntityProperty(CategoryEntity.FieldNameID, "integer", null, "primary key autoincrement"));
            entityDescription_.addProperty(new EntityProperty(CategoryEntity.FieldNameText, "text", null, "not null"));
        }
        return entityDescription_;
    }

    public static String TableFieldAliasID() {
        return String.format("%s.%s", CategoryEntity.TableName, CategoryEntity.FieldNameID);
    }

    public static String TableFieldAliasText() {
        return String.format("%s.%s", CategoryEntity.TableName, CategoryEntity.FieldNameText);
    }

    public static String entityTableName() {
        return CategoryEntity.TableName;
    }

    public static String uriAuthority() {
        return "CategoryContentProvider";
    }

    public static String uriBasePath() {
        return "categories";
    }

    public CategoryEntity(ContentResolver contentResolver) {
        super(contentResolver);
    }

    public CategoryEntity(ContentResolver contentResolver, Cursor cursor) {
        super(contentResolver, cursor);
    }

    public CategoryEntity(ContentResolver contentResolver, Uri uri) {
        super(contentResolver, uri);
        String[] projection = CategoryEntity.entityDescription().propertyNames();
        if (null != projection) {
            Cursor cursor = contentResolver.query(uri, projection, null, null, null);
            this.setCursor(cursor);
        }
    }
    private String text;

    public CategoryEntity() {
        text = null;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Override
    protected ContentValues contentValues() {
        ContentValues contentValues = new ContentValues();
        contentValues.put(RoomEntity.FieldNameText, this.getText());
        return contentValues;
    }

    @Override
    protected Uri objectsListUri() {
        return UriBuilder.objectListUri(CategoryEntity.uriAuthority(), CategoryEntity.uriBasePath());
    }

    @Override
    protected void onDataChanged(Cursor cursor) {
        // TODO Auto-generated method stub
    }
}
